package com.eastfair.auth.enumeration;

import com.eastfair.annotation.base.BaseEnum;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Getter;

import java.util.stream.Stream;

/**
 * <p>
 * 实体注释中生成的类型枚举
 * 
 * </p>
 *
 * @author ligang
 * @date 2022-09-21
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "RoleDsTypeEnum", description = "数据权限#{ALL:1,查看全部;THIS_LEVEL_CHILDER:2,本组以及子组;THIS_LEVEL:3,查本组;ASSIGN_LEVEL:4,查所指组和人;SELF:5,只查本人;-枚举")
public enum RoleDsTypeEnum implements BaseEnum {

    /**
     * ALL=1查看全部
     */
    ALL(1,"查看全部"),
    /**
     * THIS_LEVEL_CHILDER=2本组以及子组
     */
    THIS_LEVEL_CHILDER(2,"本组以及子组"),
    /**
     * THIS_LEVEL=3查本组
     */
    THIS_LEVEL(3,"查本组"),
    /**
     * ASSIGN_LEVEL=4查所指组和人
     */
    ASSIGN_LEVEL(4,"查所指组和人"),
    /**
     * SELF=5只查本人
     */
    SELF(5,"只查本人"),
    ;

    @ApiModelProperty(value = "描述")
    private int val;

    private String desc;


    /**
     * 根据当前枚举的name匹配
     */
    public static RoleDsTypeEnum match(String val, RoleDsTypeEnum def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static RoleDsTypeEnum get(String val) {
        return match(val, null);
    }

    public boolean eq(RoleDsTypeEnum val) {
        return val != null && eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "编码", allowableValues = "ALL,THIS_LEVEL_CHILDER,THIS_LEVEL,ASSIGN_LEVEL,SELF", example = "ALL")
    public String getCode() {
        return this.name();
    }

}
